/*
 * Copyright 2010 Yaroslav Klymko aka t3hnar
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package ua.t3hnar.io.serializer;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import ua.t3hnar.io.serializer.handlers.FieldHandler;

import java.lang.reflect.Field;

/**
 * @author Yaroslav Klymko aka t3hnar
 */
abstract class StreamWorker<T> {
// ------------------------------ FIELDS ------------------------------

    private static final Log LOG = LogFactory.getLog(StreamWorker.class);

    private final SerializableFieldOwner owner;
    private final Field field;
    private final FieldHandler handler;

// --------------------------- CONSTRUCTORS ---------------------------

    StreamWorker(final SerializableFieldOwner owner, final Field field, final FieldHandler handler) {
        if (owner == null || field == null || handler == null) {
            throw new IllegalArgumentException("One of the parameters is null");
        }

        LOG.debug("Initializing StreamWorker; owner: " + owner + "; field: " + field + "; handler: " + handler);

        this.owner = owner;
        this.field = field;
        this.handler = handler;
    }

// --------------------- GETTER / SETTER METHODS ---------------------

     Field getField() {
        return this.field;
    }

     FieldHandler getHandler() {
        return this.handler;
    }

     SerializableFieldOwner getOwner() {
        return this.owner;
    }

// -------------------------- OTHER METHODS --------------------------

    abstract void work(final T param) throws StreamSerializationException;
}
